package com.oocl.shopping.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DBUtil {	
	private static InitialContext ic;
	private static DataSource ds;
	private static Connection con;
	
	static{
		try {
			ic = new InitialContext();
			ds = (DataSource) ic.lookup("java:/comp/env/jdbc/myoracle");
			con = ds.getConnection();
		} catch (NamingException | SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection(){
		return con;
	}
	
	/**
	 * 
	 * @param con
	 * @param pst
	 * @param rs
	 */
	public static void close(Connection con, PreparedStatement pst, ResultSet rs){
		try {
			if(rs!=null)
				rs.close();
			if(pst!=null)
				pst.close();
			if(con!=null)
				con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
